{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c0d7037e",
   "metadata": {},
   "source": [
    "------------------------------\n",
    "* 日期：2022-09-14\\week04(周三）\n",
    "* 课程：python\n",
    "* 记录人：lin\n",
    "------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85772a8c",
   "metadata": {},
   "source": [
    "# 回顾与复习\n",
    "\n",
    "> for+range()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d5591034",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ffce5424",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建有序数值（创建自然数）\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "36191efd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))      # 产生了 5-0个值，默认从0开始"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3ba745f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(2, 5)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(2,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f26c4cef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(2,5)) # 产生了5-2 个值 ， start = 2   stop = 5   每一次增长1个单位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "acde26f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3bcbad93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 7]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(1,10,3))   # start =  2  stop = 5    每一次增长3个单位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5bd7e987",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/xxyw/index0.html\n",
      "该次停留 9 秒\n",
      "https://www.nfu.edu.cn/xxyw/index1.html\n",
      "该次停留 2 秒\n",
      "https://www.nfu.edu.cn/xxyw/index2.html\n",
      "该次停留 5 秒\n",
      "https://www.nfu.edu.cn/xxyw/index3.html\n",
      "该次停留 10 秒\n",
      "https://www.nfu.edu.cn/xxyw/index4.html\n",
      "该次停留 1 秒\n",
      "https://www.nfu.edu.cn/xxyw/index5.html\n",
      "该次停留 1 秒\n",
      "https://www.nfu.edu.cn/xxyw/index6.html\n",
      "该次停留 10 秒\n",
      "https://www.nfu.edu.cn/xxyw/index7.html\n",
      "该次停留 8 秒\n",
      "https://www.nfu.edu.cn/xxyw/index8.html\n",
      "该次停留 2 秒\n",
      "https://www.nfu.edu.cn/xxyw/index9.html\n",
      "该次停留 9 秒\n"
     ]
    }
   ],
   "source": [
    "### 实战练习：快速生成某个网站的所有网页的URL队列\n",
    "import random\n",
    "import time\n",
    "南方学院学校要闻 = \"https://www.nfu.edu.cn/xxyw/index\"\n",
    "\n",
    "页面后缀 = \".html\"\n",
    "page = 10\n",
    "\n",
    "for i in range(page):\n",
    "    print(南方学院学校要闻 + str(i) + 页面后缀)     # 字符串拼接\n",
    "    random_num = random.randint(1,10)\n",
    "    print(\"该次停留\",random_num,\"秒\")\n",
    "    time.sleep(random_num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5a9c2d10",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 总结，for+range   for可以执行循环，range决定了循环体的执行次数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd377ced",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "\n",
    ">1.random模块\n",
    ">>1. random.random():生成0-1之间的伪随机数(浮点型数)\n",
    ">>1. random.randint(a,b):生成a-b之间的随机整数(整数）\n",
    ">>1. random.chioce():随机生成一个序列中的值（非空）\n",
    "\n",
    ">2.time模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7a831476",
   "metadata": {},
   "source": [
    "# 1.random模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cb9ff4c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 1. random\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "efbd9229",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.09705657086160835"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "b5e31e96",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function random:\n",
      "\n",
      "random() method of random.Random instance\n",
      "    random() -> x in the interval [0, 1).\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.random)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "dd5eba42",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method randint in module random:\n",
      "\n",
      "randint(a, b) method of random.Random instance\n",
      "    Return random integer in range [a, b], including both end points.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "## 2. randint\n",
    "help(random.randint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b6470754",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(1,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "b2a1f783",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "1\n",
      "1\n",
      "4\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "0d9cb59e",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 3. random.choice"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "2f8b7a79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method choice in module random:\n",
      "\n",
      "choice(seq) method of random.Random instance\n",
      "    Choose a random element from a non-empty sequence.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.choice)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1aff4840",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'林裕静，邹一萌，‘梁米'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.choice (['林裕静，邹一萌，‘梁米'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6bffc92",
   "metadata": {},
   "source": [
    "# 2.time模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "dc7f068f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "14253c77",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sleep in module time:\n",
      "\n",
      "sleep(...)\n",
      "    sleep(seconds)\n",
      "    \n",
      "    Delay execution for a given number of seconds.  The argument may be\n",
      "    a floating point number for subsecond precision.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.sleep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "78fe5bb8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n",
      "world\n"
     ]
    }
   ],
   "source": [
    "print(\"hello\")\n",
    "time.sleep(3)\n",
    "print(\"world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25a87bb3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
